assertEquals(expectedValue, actualValue)
actual = "Hello";
assertEquals("Hello", actual)
actual = 11; assertEquals(10, actual)
assertNotEquals(expectedValue, actualValue)
actual = "Hello"; assertNotEquals(null, actual)
result = <condition> ? <result for true> : <result for false>
result = (5 > 3) ? "yes" : "no"
//yes
result = ("foo".equals("boo")) ? 100 : 0
//0
//Java syntax (param "aWidth") setWidth(int aWidth) //JavaScript syntax (params "firstNm", "lastNm") setName(firstNm, lastNm)
//Declared ivars in Java: public class Dog { private String name; private int age; //... } //Implicit ivars in JavaScript: class Dog { constructor(aNm, aAge) { this.name = aName; this.age = aAge; //... }
Assumption for example: Guard against "undefined" Given: value, defaultValue Is value is "undefined", then return defaultValue Else return value
let number = 0;
while (number <= 10) {
println(number);
number++;
}
class Car {
startCar() {
this.engine.startEngine();
}
}
class Engine {
startEngine() {
this.igniteCombustion();
}
}
let fct, outerThis; outerThis = this; fct = () => { return (this === outerThis); } prn("Context in function equals outer: " + fct()); //Context in function equals outer: true
class LexicalExample {
constructor() {
this.count = 0;
}
increment() {
this.count++;
}
demo() {
const fct = () => {
this.increment();
};
console.log("Before: " + this.count);
//0
fct();
fct();
console.log("After: " + this.count);
//2
}
}
(new LexicalExample()).demo();
function play() {
const a = 10;
const b = 5;
console.log(a + b);
}
https://www.abc.com/shapes/rectangle?width=10&height=2#conclusion
| Component | Example | Also Called |
|---|---|---|
| scheme | https | protocol |
| host | www.abc.com | server id or domain name |
| path | /shapes/rectangle | or folder name + web filename |
| query | width=10&height=2 | query params or search params |
| fragment identifier | conclusion | fragment - often used to "go to" a section heading within a page. |
//Examples of using a "no-args" constructor //Given object type (class) Foo //Construct object using "no-args" constructor let myFoo = new Foo(); //Given object type (class) SillyPutty //Construct object using "no-args" constructor let sp = newSillyPutty();